package gat.common.config;

import com.aliyun.agency20221216.Client;
import com.aliyun.agency20221216.models.EditEndUserStatusResponse;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;



@Configuration
@ConfigurationProperties(prefix = "ali")
@Data
public class AliConfig {
    private List<AliAccount> accounts;

    @Data
    public static class AliAccount {
        private String id;
        private String accountId;
        private String secretId;
        private String secretKey;
        private String endpoint;
    }

    public Client createClient(String primaryUId) throws Exception {
        return getAccounts().stream()
                .filter(account -> account.getAccountId().equals(primaryUId))
                .findFirst()
                .map(account -> {
                    com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                            .setAccessKeyId(account.getSecretId())
                            .setAccessKeySecret(account.getSecretKey());
                    config.endpoint = account.getEndpoint();
                    try {
                        return new Client(config);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                })
                .orElseThrow(() -> new IllegalArgumentException("No Ali account found for ID: " + primaryUId));
    }

    public static void main(String[] args) {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId("LTAI5tJN536w9VHRoXsidw9x")
                .setAccessKeySecret("8jqo64mr042E0c4eYU4Jyf5krwCUXg");
        config.endpoint = "agency.ap-southeast-1.aliyuncs.com";
        Client client = null;
        try {
            client = new Client(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        com.aliyun.agency20221216.models.EditEndUserStatusRequest editEndUserStatusRequest = new com.aliyun.agency20221216.models.EditEndUserStatusRequest()
                .setUid(5402442381710127L)
                .setCreditStatus("postPayThaw");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            EditEndUserStatusResponse editEndUserStatusResponse = client.editEndUserStatusWithOptions(editEndUserStatusRequest, runtime);
            System.out.println(editEndUserStatusResponse);
        }catch (Exception _error) {
            System.out.println("111");
        }
    }
}

